/**
 * FileName: productTypeEnum
 * Author: Wb
 * Date: 2025/9/24 10:13
 * Description:
 * History:
 */
package org.test.device.constant;

import lombok.Getter;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 〈一句话功能简述〉<br>
 * 〈商品；类型枚举类〉
 *
 * @author Wb
 * @create 2025/9/24
 * @since 1.0.0
 */
@Getter
public enum ProductTypeEnum {

    MACHINE_TOOL(0,"machine tool","机床类设备"),
    COATING_EQUIPMENT(1, "coating equipment","涂装类设备"),
    HEAT_TREATMENT_EQUIPMENT(2, "heat treatment equipment","热处理类设备"),
    LIFTING_CATEGORY(3, "lifting category","起重类设备");

    private final int type;
    private final String enName;
    private final String cnName;

    //缓存映射关系，提高查询效率
    private static final Map<Integer, ProductTypeEnum> TYPE_MAP = new HashMap<>();
    private static final Map<String, ProductTypeEnum> EN_NAME_MAP = new HashMap<>();
    private static final Map<String, ProductTypeEnum> CN_NAME_MAP = new HashMap<>();

    //静态初始化缓存
    static {
        for (ProductTypeEnum enumItem : ProductTypeEnum.values()) {
            TYPE_MAP.put(enumItem.type, enumItem);
            EN_NAME_MAP.put(enumItem.enName, enumItem);
            CN_NAME_MAP.put(enumItem.cnName, enumItem);
        }
    }

    ProductTypeEnum(int type,String enName,String cnName){
        this.type=type;
        this.enName=enName;
        this.cnName=cnName;
    }


    /**
     * @Author Wb
     * @Description 根据类型值获取枚举实例
     * @Date 10:51 2025/9/24
     * @Param type 类型值
     * @Return 对应的枚举实例，不存在则返回null
     */
    public static ProductTypeEnum getByType(int type) {
        return TYPE_MAP.get(type);
    }


    /**
     * @Author Wb
     * @Description 根据英文名称获取枚举实例
     * @Date 10:53 2025/9/24
     * @Param enName 英文名称
     * @Return 对应的枚举实例，不存在则返回null
     */
    public static ProductTypeEnum getByEnName(String enName) {
        return EN_NAME_MAP.get(enName);
    }

    /**
     * @Author Wb
     * @Description 根据中文名称获取枚举实例
     * @Date 10:53 2025/9/24
     * @Param cnName 中文名称
     * @Return 对应的枚举实例，不存在则返回null
     */
    public static ProductTypeEnum getByCnName(String cnName) {
        return CN_NAME_MAP.get(cnName);
    }

    /**
     * @Author Wb
     * @Description 返回所有类型
     * @Date 14:32 2025/9/24
     * @Return 返回所有商品类型
     */
    public static List<ProductTypeEnum> getAllTypes() {
        return Arrays.asList(values());
    }
}
